package com.accenture.fd.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.accenture.fd.entity.User;
import com.accenture.fd.service.UserService;

@CrossOrigin
@RestController
public class LoginController {

	@Autowired
	private UserService service;

	@RequestMapping(value = "/login")
	public String login(HttpServletRequest request) {

		String userId = request.getParameter("userId");

		User user = service.getUser(userId);
		
		return user.getPassword();

	}

	@RequestMapping(value = "/save")
	public void save(HttpServletRequest request) {

		String userId = request.getParameter("userId");
		String password = request.getParameter("password");

		service.saveUser(userId,password);

	}
	
}
